<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit"/>
    <title>电脑商城</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="../css/layout.css"/>
    <link rel="stylesheet" type="text/css" href="../css/top.css"/>
    <link rel="stylesheet" type="text/css" href="../css/footer.css"/>
    <link rel="stylesheet" type="text/css" href="../css/order.css"/>
</head>

<body>
<!--头部-->
<header class="header">
    <!--电脑商城logo-->
    <div class="row">
        <div class="col-md-3">
            <a href="index_user.html">
                <img src="../images/index/stumalllogo.png"/>
            </a>
        </div>
        <!--快捷选项-->
        <div class="col-md-9 top-item">
            <ul class="list-inline pull-right">

                <li><a href="orders_user.html"><span class="fa fa-file-text"></span>&nbsp;订单</a></li>
                <li class="li-split">|</li>
                <li><a href="cart_user.html"><span class="fa fa-cart-plus"></span>&nbsp;购物车</a></li>
                <li class="li-split">|</li>
                <li>
                    <!--下列列表按钮 ：管理-->
                    <div class="btn-group">
                        <button type="button" class="btn btn-link dropdown-toggle" data-toggle="dropdown">
                            <span id="top-dropdown-btn"><span class="fa fa-gears"></span>&nbsp;管理 <span
                                    class="caret"></span></span>
                        </button>
                        <ul class="dropdown-menu top-dropdown-ul" role="menu">
                            <li><a href="password.html">修改密码</a></li>
                            <li><a href="userdata.html">个人资料</a></li>
                            <li><a href="upload.html">上传头像</a></li>
                            <li><a href="address.html">收货管理 </a></li>
                        </ul>
                    </div>
                </li>
                <li class="li-split">|</li>
                <li><a href="login.html"><span class="fa fa-user"></span>&nbsp;登录</a></li>
            </ul>
        </div>
    </div>
</header>
<!--导航 -->
<!--分割导航和顶部-->
<div class="row top-nav">
    <div class="col-md-6">
        <ul class="nav nav-pills">
            <li>
                <a href="#"></a>
            </li>
            <li class="active"><a href="index_user.html"><span class="fa fa-home"></span></a></li>
            <form id="form-search" action="search.html" class="form-inline pull-right" role="form">
                <div class="form-group">
                    <input type="text" class="form-control" id="search" name="title" placeholder="请输入商品名称进行搜索">
                </div>
                <input id="btn-search" type="submit" class="btn btn-primary" value="搜索" />
            </form>
        </ul>
    </div>
</div>
<!--头部结束-->
<!--导航结束-->
<div class="container">
    <div class="col-md-2">
        <!--左侧导航开始-->
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <!--主选项：我的订单-->
                    <p class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">我的订单</a>
                    </p>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <div><a href="orders_user.html"><b>全部订单</b></a></div>

                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <!--主选项：资料修改-->
                    <p class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">资料修改</a>
                    </p>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div><a href="password.html"><b>修改密码</b></a></div>
                        <div><a href="userdata.html">个人资料</a></div>
                        <div><a href="upload.html">上传头像</a></div>
                        <div><a href="address.html">收货管理</a></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--左侧导航结束-->
    <div class="col-md-10">
        <div class="panel panel-default">

            <div class="panel-body">
                <form action="orderInfo.html" role="form">
                    <table class="orders-table" width="101%">
                        <thead>
                        <tr>
                            <th width="5%">用户id</th>
                            <th width="5%"></th>
                            <th width="30%">商品</th>
                            <th width="10%">单价</th>
                            <th width="10%">数量</th>
                            <th width="10%">小计</th>
                            <th width="10%">售后</th>
                            <th width="10%">状态</th>
                            <th width="20%">操作</th>
                        </tr>
                        </thead>
                        <tbody id="order-list" class="orders-body">
                        <tr>
                            <td>1</td>
                            <td><img src="../images/portal/12DELLXPS13-silvery/collect.png" class="img-responsive"/></td>
                            <td>联想(Lenovo)小新Air13 Pro 13.3英寸14.8mm超轻薄笔记本电脑</td>
                            <td>¥<span>5298</span></td>
                            <td>1件</td>
                            <td>¥<span>5298</span></td>
                            <td><a href="#">申请售后</a></td>
                            <td>
                                <!--                                <div class="hide" id="1">已发货</div><div class="hide" id="2">待收货</div><div class="hide" id="3">运输中</div><div class="hide" id="4">已收货</div><div class="hide" id="5">交易完成</div>-->
                                <div><input type="submit" name="uid" value="#{uid}">订单详情</a></div>
                            </td>
                            <td><a href="#" class="btn btn-default btn-xs">收货</a></td>
                        </tr>
                        </tbody>
                    </table>

                </form>

                <div>
                    <span id="all-price" class="pull-right">123</span><span class="pull-right">总金额:</span>
                </div>
            </div>
        </div>

    </div>
</div>

</div>
<script type="text/javascript">

    $(document).ready(function () {
        showOrderList();
    });

    function showOrderList() {
        $("#order-list").empty();

        $.ajax({
            url: "/order/listu",
            type: "GET",
            dataType: "JSON",
            success: function (json) {

                console.log(json.data);
                let list = json.data;
                console.log("count=" + list.length);

                let allPrice = 0;
                for (let i=0;i<list.length;i++){
                    console.log(list[i].uid);
                    let tr='<tr>\n' +
                        '<td>#{uid}</td>'+
                        '                         <td><img src="..#{image}collect.png" class="img-responsive" /></td>' +
                        '                        <td>#{title}</td>' +
                        '                        <td>¥<span>#{price}</span></td>' +
                        '                        <td>#{num}</td>\n' +
                        '                        <td>¥<span>#{prices}</span></td>' +
                        '                        <td><a href="#">申请售后</a></td>\n' +
                        '                        <td>\n' +
                        '                            <div onclick="pStatus(#{oid},#{pid})">#{pStatus}</div>\n' +
                        // '                            <div><input type="submit" name="uid" value="pStatus(#{oid},#{pid})" ><input type="submit" name="pid" value="#{pid}" >订单详情</></div>\n' +
                        '                        </td>\n' +
                        '                        <td><a href="#" class="btn btn-default btn-xs">确认收货</a></td>\n' +
                        '                    </tr>';
                    tr = tr.replace(/#{uid}/g, list[i].uid);
                    tr = tr.replace(/#{oid}/g, list[i].oid);
                    tr = tr.replace(/#{pid}/g, list[i].pid);
                    tr = tr.replace(/#{image}/g, list[i].image);
                    tr = tr.replace(/#{title}/g, list[i].title);
                    tr = tr.replace(/#{price}/g, list[i].price);
                    tr = tr.replace(/#{num}/g, list[i].num);
                    tr = tr.replace(/#{prices}/g, list[i].price * list[i].num);

                    if(list[i].pStatus==0){
                        tr=tr.replace(/#{pStatus}/g,"未发货");
                    }else if(list[i].pStatus==1){
                        tr=tr.replace(/#{pStatus}/g,"已发货");
                    }else if(list[i].pStatus==2){
                        tr=tr.replace(/#{pStatus}/g,"运输中");
                    }else if(list[i].pStatus==3){
                        tr=tr.replace(/#{pStatus}/g,"待收货");
                    }else if(list[i].pStatus==4){
                        tr=tr.replace(/#{pStatus}/g,"已收货");
                    }else if(list[i].pStatus==5){
                        tr=tr.replace(/#{pStatus}/g,"交易完成");
                    }

                    $("#order-list").append(tr);
                    allPrice += list[i].price * list[i].num;
                }
                $("#all-price").html(allPrice);
            }
        });
    }

    function pStatus(oid,pid) {
        console.log("商品状态");
        $.ajax({
            url:"/order/p_status",
            type:"POST",
            data:oid,pid,
            dataType:"JSON",
            success:function (json) {
                /*alert(json.state)*/
                if(json.state==200){
                    alert("审核通过");
                    showUserList();
                }else {
                    alert("审核异常")
                }
            },
            error:function (xhr) {
                alert("审核产生未知的异常"+xhr.message);//自动产生错误描述信息
            }
        })
    }

</script>
</body>

</html>